package com.lagou.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author 黄子濠
 * @date 2020/8/17 23:23
 */
@Component
public class BeanUtils implements ApplicationContextAware {
    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }
    //获得applicationContext
    public static ApplicationContext getApplicationContext() {
        return context;
    }

    public static Object getBeanByType(String type) {
        Object object = null;
        object = getApplicationContext().getBean(type);
        return object;
    }
}
